//
//  ZPFirstStartViewController.m
//  ZPIOSEducation
//
//  Created by hh on 2016/11/23.
//  Copyright © 2016年 mini1. All rights reserved.
//

#import "ZPFirstStartViewController.h"
#import "ZPAppDelegate.h"
#import "ZPShareView.h"
#import "ZPBaseTabBarController.h"
#import "ZPBaseNavigationController.h"
#import "ZPRegisterLoginViewController.h"

// 初次启动 或 新特性滚动图片个数4
#define zStartImageCount 4


@interface ZPFirstStartViewController ()<UIScrollViewDelegate>
{
    UIScrollView  *startScrollView;
//    UIPageControl *startPageControl;
}

@end

@implementation ZPFirstStartViewController



#pragma mark - <视图已经加载viewDidLoad>
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupStartScrollView];
}


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
}


#pragma mark - <首次启动滚动图>
- (void)setupStartScrollView
{
    startScrollView = [[UIScrollView alloc] init];
    startScrollView.frame = CGRectMake(0, 0, Main_Screen_Width, Main_Screen_Height);
    startScrollView.contentSize = CGSizeMake(zStartImageCount*Main_Screen_Width, 0);
    startScrollView.bounces = YES;
    startScrollView.pagingEnabled = YES;
    startScrollView.showsHorizontalScrollIndicator = NO;
    [self.view addSubview:startScrollView];
    
    NSString *imageNameHeader;
    if (iPhone5) {
        imageNameHeader = @"lead_phone5_0";
    } else if (iPhone6) {
        imageNameHeader = @"lead_phone6_0";
    } else if (iPhone6_Plus) {
        imageNameHeader = @"lead_phone6p_0";
    } else {
        imageNameHeader = @"lead_phone4_0";
    }
    
    for (int i=0; i < zStartImageCount; i++) {
        UIImageView *startImageView = [[UIImageView alloc] initWithFrame:CGRectMake(Main_Screen_Width*i, 0, Main_Screen_Width, Main_Screen_Height)];
        [startImageView setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@%ld",imageNameHeader,(long)i+1]]];
        startImageView.contentMode = UIViewContentModeScaleAspectFill;
        startImageView.clipsToBounds = YES;
        startImageView.userInteractionEnabled = YES;
//        startImageView.image = [UIImage imageNamed:self.startImages[i]];
        [startScrollView addSubview:startImageView];
        if (i == zStartImageCount - 1) { // 在最后一个imageView里添加子视图
            [self setupSubViewsAtImageView:startImageView];
        }
    }
    startScrollView.delegate = self; // 设置代理
//    [self setupStartPageControl]; // 加载分页控制器
}


#pragma mark - <添加开始学习button>
- (void)setupSubViewsAtImageView:(UIImageView *)imgView {
    imgView.userInteractionEnabled = YES; // 用户交互
    UIButton *experienceBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [[ZPShareView sharedSingleView] setupButton:experienceBtn  backgroundColor:[UIColor  colorWithRed:22/255. green:192/255. blue:193/255. alpha:1.] image:nil title:@"立即进入" titltColor:white_color titleFont:18];
    ViewRadius(experienceBtn, 18.);
//    experienceBtn.bounds = CGRectMake(0, 0, Main_Screen_Width / 2, 44);
//    experienceBtn.center = CGPointMake(self.startScrollView.center.x, Main_Screen_Height*0.9);
    [experienceBtn addTarget:self action:@selector(startlearningClick) forControlEvents:UIControlEventTouchUpInside];
    [imgView addSubview:experienceBtn];
    [experienceBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        if (iPhone5) {
            make.height.equalTo(@38);
        } else if (iPhone6) {
            make.height.equalTo(@44);
        } else if (iPhone6_Plus) {
            make.height.equalTo(@49);
        }
        make.width.equalTo(@(WIDTH(imgView) / 2));
        make.centerY.equalTo(@(imgView.xj_centerY * 0.8));
        make.centerX.equalTo(imgView.mas_centerX);
    }];
}


#pragma mark - <点击开始学习按钮进入登录和注册界面>
- (void)startlearningClick {
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    window.rootViewController = [[ZPBaseTabBarController alloc] init];
}


//#pragma 设置pageControll
//// 分页控制器
//- (void)setupStartPageControl {
//    startPageControl = [[UIPageControl alloc] init];
//    startPageControl = [[UIPageControl alloc] init];
//    startPageControl.numberOfPages = zStartImageCount;
//    startPageControl.currentPage = 0;
//    startPageControl.currentPageIndicatorTintColor = zMainColor;
//    startPageControl.pageIndicatorTintColor = zFreeColor(210, 210, 210, 1);
//    CGSize size = [startPageControl sizeForNumberOfPages:zStartImageCount];
//    startPageControl.bounds = CGRectMake(0, 0, size.width, size.height);
//    CGFloat pageH = HEIGHT(startScrollView) * 0.8;
//    startPageControl.center = CGPointMake(CENTER_X(self.view), pageH);
//    [self.view addSubview:startPageControl];
//}
//
//#pragma UIScrollViewDelegate回调方法:scrollView开始滚动
//// scrollView已经开始滚动
//- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
//    startPageControl.currentPage = (startScrollView.contentOffset.x + Main_Screen_Width / 2) / Main_Screen_Width;
//}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
